<?php


header("Content-type: text/html; charset=utf-8");
require_once __DIR__ . '\\function.php';
require_once __DIR__ . '\\TestClass.php';

$class_name = 'TestClass';

$reflection = new ReflectionClass($class_name);
//通过反射获取类的注释
$doc = $reflection->getDocComment();
//解析类的注释头
$parase_result = DocParserFactory::getInstance()->parse($doc);
$class_metadata = $parase_result;

//输出测试
var_dump($doc);
echo "\r\n";
var_dump($parase_result);
echo "\r\n-----------------------------------\r\n";

//获取类中的方法，设置获取public,protected类型方法
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC + ReflectionMethod::IS_PROTECTED + ReflectionMethod::IS_PRIVATE);
//遍历所有的方法
foreach ($methods as $method) {
    //获取方法的注释
    $doc = $method->getDocComment();
    //解析注释
    $info = DocParserFactory::getInstance()->parse($doc);
    $metadata = $class_metadata + $info;
    //获取方法的类型
    $method_flag = $method->isProtected(); //还可能是public,protected类型的
    //获取方法的参数
    $params = $method->getParameters();
    $position = 0; //记录参数的次序
    foreach ($params as $param) {
        $arguments[$param->getName()] = $position;
        //参数是否设置了默认参数，如果设置了，则获取其默认值
        $defaults[$position] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
        $position++;
    }

    $call = array(
//        'class_name' => $class_name,
//        'method_name' => $method->getName(),
//        'arguments' => $arguments,
//        'defaults' => $defaults,
        'method_desc' => $metadata['desc'],
//        'method_flag' => $method_flag,
    );
    echo "<pre>";
    var_dump($call);
    echo "</pre>";
    echo "\r\n-----------------------------------\r\n";
}
